package com.atmilan.quartz.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atmilan.quartz.mapper.ManifestProductSkuSupplierMapper;
import com.atmilan.quartz.mapper.MerchantSupplierMapper;
import com.atmilan.quartz.mapper.SupplierMapper;
import com.atmilan.quartz.model.dto.buyer.MerchantProductSkuDTO;
import com.atmilan.quartz.model.dto.buyer.ProductSkuDTO;
import com.atmilan.quartz.model.dto.buyer.SupplierDTO;
import com.atmilan.quartz.model.dto.buyer.SupplierPriceDTO;
import com.atmilan.quartz.model.entity.buyer.Merchant;
import com.atmilan.quartz.model.entity.buyer.MerchantCustomer;
import com.atmilan.quartz.model.entity.buyer.MerchantSupplier;
import com.atmilan.quartz.model.entity.buyer.MerchantSupplierExample;
import com.atmilan.quartz.model.entity.buyer.ProductSkuSupplier;
import com.atmilan.quartz.service.IMerchantCustomerService;
import com.atmilan.quartz.service.IMerchantService;
import com.atmilan.quartz.service.IMerchantSupplierService;
import com.atmilan.quartz.service.IProductSkuService;
import com.atmilan.quartz.service.IProductSkuSupplierService;
import com.atmilan.quartz.service.ISupplierService;

@Service
public class MerchantSupplierServiceImpl implements IMerchantSupplierService {
    @Autowired
    MerchantSupplierMapper merchantSupplierMapper;
    @Autowired
    SupplierMapper supplierMapper;
    @Autowired
    IProductSkuSupplierService productSkuSupplierService;
    @Autowired
    IProductSkuService productSkuService;
    @Autowired
    IMerchantService merchantService;
    @Autowired
    ManifestProductSkuSupplierMapper manifestProductSkuSupplierMapper;
    @Autowired
    ISupplierService supplierService;
    @Autowired
    IMerchantCustomerService merchantCustomerService;

    /**
     * 获取商户 该商户下 所有供应商对该产品的报价 首页查询使用的
     * @param merchantId
     * @return
     */
    @Override
    public List<MerchantProductSkuDTO> getByMerchantIdAndProductId(Long merchantId, Long productId, Map<Long, String> supplierAll, List<ProductSkuSupplier> productSkuSuppliers, Map<Long, List<MerchantSupplier>> map, Map<String, List<MerchantSupplier>> mm1, Map<Long, List<MerchantSupplier>> getByMerchantIdAndStateTrue, Map<String, MerchantCustomer> mmc, Map<Long, List<ProductSkuDTO>> sku) {
        List<MerchantProductSkuDTO> listMerchantProductSkuDTO = new ArrayList<MerchantProductSkuDTO>();

        List<ProductSkuDTO> listSku = sku.get(productId);
        for (ProductSkuDTO productSkuDTO : listSku) {

            List<SupplierPriceDTO> result = new ArrayList<>();
            List<MerchantSupplier> list = getByMerchantIdAndStateTrue.get(merchantId);
            for (MerchantSupplier merchantSupplier : list) {

                if (merchantSupplier.getSupplierType() == 0) {
                    //直属供应商
                    List<ProductSkuSupplier> listProductSkuSupplier = productSkuSupplierService.getBySkuIdAndSupplierIdAndOnSaleStatusAndStockGreater0(productSkuDTO.getId(), merchantSupplier.getSupplierId(), 1, productSkuSuppliers);
                    //同一个供应商对同一个sku 有不同的报价
                    for (ProductSkuSupplier productSkuSupplier : listProductSkuSupplier) {
                        SupplierPriceDTO supplierPriceDTO = new SupplierPriceDTO();
                        //SupplierDTO supplier= supplierService.getSupplierById(merchantSupplier.getSupplierId());
                        supplierPriceDTO.setDeliverAddress(productSkuSupplier.getDeliverAddress());
                        supplierPriceDTO.setMarkupRate(new BigDecimal(0));
                        supplierPriceDTO.setSupplierName(supplierAll.get(merchantSupplier.getSupplierId()));
                        supplierPriceDTO.setId(merchantSupplier.getId());
                        supplierPriceDTO.setPrice(productSkuSupplier.getPrice());// 获取该供应商对这个sku 的报价
                        supplierPriceDTO.setSkuId(productSkuDTO.getId());
                        supplierPriceDTO.setSkuJson(productSkuDTO.getSkuJson());
                        supplierPriceDTO.setProductSkuSupplierId(productSkuSupplier.getId());
                        supplierPriceDTO.setMerchantSupplierId(merchantSupplier.getId());
                        supplierPriceDTO.setSupplierId(productSkuSupplier.getSupplierId());
                        supplierPriceDTO.setStoke(productSkuSupplier.getStock());
                        supplierPriceDTO.setMerchantSupplierPriceId(merchantSupplier.getId());

                        result.add(supplierPriceDTO);
                    }

                } else {
                    //直属商户
                    //查找 直属商户的供应商

                    Merchant merchant = merchantService.getById(merchantSupplier.getParentMerchantId());
                    String supplierName = merchant.getMerchantName();
                    //获取这个商户的供应商
                    //直属商户的供应商列表
                    List<MerchantSupplier> list1 = map.containsKey(merchant.getId()) ? map.get(merchant.getId()) : new ArrayList<MerchantSupplier>();
                    for (MerchantSupplier merchantSupplier1 : list1) {
                        List<ProductSkuSupplier> listProductSkuSupplier = productSkuSupplierService.getBySkuIdAndSupplierIdAndOnSaleStatusAndStockGreater0(productSkuDTO.getId(), merchantSupplier1.getSupplierId(), 1, productSkuSuppliers);
                        //同一个供应商对同一个sku 有不同的报价
                        for (ProductSkuSupplier productSkuSupplier : listProductSkuSupplier) {
                            SupplierPriceDTO supplierPriceDTO = new SupplierPriceDTO();
                            //SupplierDTO supplier= supplierService.getSupplierById(merchantSupplier1.getSupplierId());
                            supplierPriceDTO.setDeliverAddress(productSkuSupplier.getDeliverAddress());
                            supplierPriceDTO.setMarkupRate(new BigDecimal(0));
                            supplierPriceDTO.setSupplierName(supplierName);
                            supplierPriceDTO.setId(merchantSupplier1.getId());
                            supplierPriceDTO.setPrice(productSkuSupplier.getPrice().add(productSkuSupplier.getPrice().multiply(merchantSupplier.getMarkupRate())));// 获取该供应商对这个sku 的报价
                            supplierPriceDTO.setSkuId(productSkuDTO.getId());
                            supplierPriceDTO.setSkuJson(productSkuDTO.getSkuJson());
                            supplierPriceDTO.setProductSkuSupplierId(productSkuSupplier.getId());
                            supplierPriceDTO.setMerchantSupplierId(merchantSupplier.getId());
                            supplierPriceDTO.setSupplierId(productSkuSupplier.getSupplierId());
                            supplierPriceDTO.setMerchantSupplierPriceId(merchantSupplier1.getId());
                            supplierPriceDTO.setStoke(productSkuSupplier.getStock());

                            result.add(supplierPriceDTO);
                        }
                    }
                    //查找这个直属商户的上一级
                    if (merchant.getParentIds() != null && !merchant.getParentIds().equals("0")) {
                        String[] ids = merchant.getParentIds().split(",");
                        for (String id : ids) {
                            if (!id.equals("0")) {
                                // 该ID 是上级邀请的 判断这个ID 是否禁用
                                List<MerchantSupplier> suppliers = mm1.get(merchant.getId() + Long.valueOf(id) + "");
                                if (suppliers.size() == 0) {
                                    //禁用的
                                    continue;
                                }
                                //查找  id 给 merchant.getId(); 加价率
                                MerchantCustomer merchantCustomer = mmc.get(Long.valueOf(id) + merchant.getContactsMobilePhone());
                                Long lid = Long.valueOf(id);
                                if (!lid.equals(merchantId)) {
                                    List<MerchantSupplier> BBB = map.containsKey(lid) ? map.get(lid) : new ArrayList<MerchantSupplier>();
                                    for (MerchantSupplier merchantSupplier1 : BBB) {
                                        List<ProductSkuSupplier> listProductSkuSupplier = productSkuSupplierService.getBySkuIdAndSupplierIdAndOnSaleStatusAndStockGreater0(productSkuDTO.getId(), merchantSupplier1.getSupplierId(), 1, productSkuSuppliers);
                                        //同一个供应商对同一个sku 有不同的报价
                                        for (ProductSkuSupplier productSkuSupplier : listProductSkuSupplier) {
                                            SupplierPriceDTO supplierPriceDTO = new SupplierPriceDTO();
                                            //SupplierDTO supplier = supplierService.getSupplierById(merchantSupplier1.getSupplierId());
                                            supplierPriceDTO.setDeliverAddress(productSkuSupplier.getDeliverAddress());
                                            supplierPriceDTO.setMarkupRate(new BigDecimal(0));
                                            supplierPriceDTO.setSupplierName(supplierName);
                                            supplierPriceDTO.setId(merchantSupplier1.getId());
                                            BigDecimal price1 = productSkuSupplier.getPrice().add(productSkuSupplier.getPrice().multiply(merchantSupplier.getMarkupRate()));
                                            // merchantSupplier1  给 merchantSupplier 的加价率是多少
                                            price1 = price1.add(price1.multiply(merchantCustomer.getMarkupRate()));//二次加价
                                            supplierPriceDTO.setPrice(price1);// 获取该供应商对这个sku 的报价
                                            supplierPriceDTO.setSkuId(productSkuDTO.getId());
                                            supplierPriceDTO.setSkuJson(productSkuDTO.getSkuJson());
                                            supplierPriceDTO.setProductSkuSupplierId(productSkuSupplier.getId());
                                            supplierPriceDTO.setMerchantSupplierId(merchantSupplier.getId());
                                            supplierPriceDTO.setMerchantSupplierPriceId(merchantSupplier1.getId());
                                            supplierPriceDTO.setSupplierId(productSkuSupplier.getSupplierId());
                                            supplierPriceDTO.setStoke(productSkuSupplier.getStock());

                                            result.add(supplierPriceDTO);
                                        }
                                    }
                                }
                            }
                        }
                    }

                }
            }
            MerchantProductSkuDTO merchantProductSkuDTO = new MerchantProductSkuDTO();

            merchantProductSkuDTO.setSkuId(productSkuDTO.getId());
            merchantProductSkuDTO.setSkuJson(productSkuDTO.getSkuJson());
            merchantProductSkuDTO.setSupplierList(result);
            listMerchantProductSkuDTO.add(merchantProductSkuDTO);

        }
        return listMerchantProductSkuDTO;
    }

    @Override
    public boolean updateById(MerchantSupplier merchantSupplier) {
        merchantSupplier.setUpdateTime(new Date());

        return merchantSupplierMapper.updateByPrimaryKeySelective(merchantSupplier) > 0;
    }

    /**
     * 获取商户 该商户下 所有供应商对该产品的报价
     * @param merchantId
     * @return
     */
    @Override
    public List<MerchantProductSkuDTO> getByMerchantIdAndProductId(Long merchantId, Long productId) {
        List<MerchantProductSkuDTO> listMerchantProductSkuDTO = new ArrayList<MerchantProductSkuDTO>();

        List<ProductSkuDTO> listSku = productSkuService.getProductSkuByProductId(productId);
        for (ProductSkuDTO productSkuDTO : listSku) {

            List<SupplierPriceDTO> result = new ArrayList<>();
            List<MerchantSupplier> list = getByMerchantIdAndStateTrue(merchantId);
            for (MerchantSupplier merchantSupplier : list) {

                if (merchantSupplier.getSupplierType() == 0) {
                    //直属供应商

                    List<ProductSkuSupplier> listProductSkuSupplier = productSkuSupplierService.getBySkuIdAndSupplierIdAndOnSaleStatusAndStockGreater0(productSkuDTO.getId(), merchantSupplier.getSupplierId(), 1);
                    //同一个供应商对同一个sku 有不同的报价
                    for (ProductSkuSupplier productSkuSupplier : listProductSkuSupplier) {
                        SupplierPriceDTO supplierPriceDTO = new SupplierPriceDTO();
                        SupplierDTO supplier = supplierService.getSupplierById(merchantSupplier.getSupplierId());
                        supplierPriceDTO.setDeliverAddress(productSkuSupplier.getDeliverAddress());
                        supplierPriceDTO.setMarkupRate(new BigDecimal(0));
                        supplierPriceDTO.setSupplierName(supplier.getSupplierName());
                        supplierPriceDTO.setId(merchantSupplier.getId());
                        supplierPriceDTO.setPrice(productSkuSupplier.getPrice());// 获取该供应商对这个sku 的报价
                        supplierPriceDTO.setSkuId(productSkuDTO.getId());
                        supplierPriceDTO.setSkuJson(productSkuDTO.getSkuJson());
                        supplierPriceDTO.setProductSkuSupplierId(productSkuSupplier.getId());
                        supplierPriceDTO.setMerchantSupplierId(merchantSupplier.getId());
                        supplierPriceDTO.setSupplierId(productSkuSupplier.getSupplierId());
                        supplierPriceDTO.setStoke(productSkuSupplier.getStock());
                        supplierPriceDTO.setMerchantSupplierPriceId(merchantSupplier.getId());

                        result.add(supplierPriceDTO);
                    }

                } else {
                    //直属商户
                    //查找 直属商户的供应商

                    Merchant merchant = merchantService.getById(merchantSupplier.getParentMerchantId());
                    String supplierName = merchant.getMerchantName();
                    //获取这个商户的供应商
                    //直属商户的供应商列表
                    List<MerchantSupplier> list1 = getByMerchantIdAndSupplierTypeIs0(merchant.getId());
                    for (MerchantSupplier merchantSupplier1 : list1) {
                        List<ProductSkuSupplier> listProductSkuSupplier = productSkuSupplierService.getBySkuIdAndSupplierIdAndOnSaleStatusAndStockGreater0(productSkuDTO.getId(), merchantSupplier1.getSupplierId(), 1);
                        //同一个供应商对同一个sku 有不同的报价
                        for (ProductSkuSupplier productSkuSupplier : listProductSkuSupplier) {
                            SupplierPriceDTO supplierPriceDTO = new SupplierPriceDTO();
                            //SupplierDTO supplier= supplierService.getSupplierById(merchantSupplier1.getSupplierId());
                            supplierPriceDTO.setDeliverAddress(productSkuSupplier.getDeliverAddress());
                            supplierPriceDTO.setMarkupRate(new BigDecimal(0));
                            supplierPriceDTO.setSupplierName(supplierName);
                            supplierPriceDTO.setId(merchantSupplier1.getId());
                            supplierPriceDTO.setPrice(productSkuSupplier.getPrice().add(productSkuSupplier.getPrice().multiply(merchantSupplier.getMarkupRate())));// 获取该供应商对这个sku 的报价
                            supplierPriceDTO.setSkuId(productSkuDTO.getId());
                            supplierPriceDTO.setSkuJson(productSkuDTO.getSkuJson());
                            supplierPriceDTO.setProductSkuSupplierId(productSkuSupplier.getId());
                            supplierPriceDTO.setMerchantSupplierId(merchantSupplier.getId());
                            supplierPriceDTO.setSupplierId(productSkuSupplier.getSupplierId());
                            supplierPriceDTO.setMerchantSupplierPriceId(merchantSupplier1.getId());
                            supplierPriceDTO.setStoke(productSkuSupplier.getStock());

                            result.add(supplierPriceDTO);
                        }
                    }
                    //查找这个直属商户的上一级
                    if (merchant.getParentIds() != null && !merchant.getParentIds().equals("0")) {
                        String[] ids = merchant.getParentIds().split(",");
                        for (String id : ids) {
                            if (!id.equals("0")) {
                                // 该ID 是上级邀请的 判断这个ID 是否禁用
                                List<MerchantSupplier> suppliers = getByMerchantIdAndParentIdAndStateTrue(merchant.getId(), Long.valueOf(id));
                                if (suppliers.size() == 0) {
                                    //禁用的
                                    continue;
                                }
                                //查找  id 给 merchant.getId(); 加价率
                                MerchantCustomer merchantCustomer = merchantCustomerService.getByContactsMobilePhoneAndMerchantId(merchant.getContactsMobilePhone(), Long.valueOf(id));

                                if (Long.valueOf(id) != merchantId) {
                                    List<MerchantSupplier> BBB = getByMerchantIdAndSupplierTypeIs0(Long.valueOf(id));
                                    for (MerchantSupplier merchantSupplier1 : BBB) {
                                        List<ProductSkuSupplier> listProductSkuSupplier = productSkuSupplierService.getBySkuIdAndSupplierIdAndOnSaleStatusAndStockGreater0(productSkuDTO.getId(), merchantSupplier1.getSupplierId(), 1);
                                        //同一个供应商对同一个sku 有不同的报价
                                        for (ProductSkuSupplier productSkuSupplier : listProductSkuSupplier) {
                                            SupplierPriceDTO supplierPriceDTO = new SupplierPriceDTO();
                                            //SupplierDTO supplier = supplierService.getSupplierById(merchantSupplier1.getSupplierId());
                                            supplierPriceDTO.setDeliverAddress(productSkuSupplier.getDeliverAddress());
                                            supplierPriceDTO.setMarkupRate(new BigDecimal(0));
                                            supplierPriceDTO.setSupplierName(supplierName);
                                            supplierPriceDTO.setId(merchantSupplier1.getId());
                                            BigDecimal price1 = productSkuSupplier.getPrice().add(productSkuSupplier.getPrice().multiply(merchantSupplier.getMarkupRate()));
                                            // merchantSupplier1  给 merchantSupplier 的加价率是多少
                                            price1 = price1.add(price1.multiply(merchantCustomer.getMarkupRate()));//二次加价
                                            supplierPriceDTO.setPrice(price1);// 获取该供应商对这个sku 的报价
                                            supplierPriceDTO.setSkuId(productSkuDTO.getId());
                                            supplierPriceDTO.setSkuJson(productSkuDTO.getSkuJson());
                                            supplierPriceDTO.setProductSkuSupplierId(productSkuSupplier.getId());
                                            supplierPriceDTO.setMerchantSupplierId(merchantSupplier.getId());
                                            supplierPriceDTO.setMerchantSupplierPriceId(merchantSupplier1.getId());
                                            supplierPriceDTO.setSupplierId(productSkuSupplier.getSupplierId());
                                            supplierPriceDTO.setStoke(productSkuSupplier.getStock());

                                            result.add(supplierPriceDTO);
                                        }
                                    }
                                }
                            }
                        }
                    }

                }
            }
            MerchantProductSkuDTO merchantProductSkuDTO = new MerchantProductSkuDTO();

            merchantProductSkuDTO.setSkuId(productSkuDTO.getId());
            merchantProductSkuDTO.setSkuJson(productSkuDTO.getSkuJson());
            merchantProductSkuDTO.setSupplierList(result);
            listMerchantProductSkuDTO.add(merchantProductSkuDTO);

        }
        return listMerchantProductSkuDTO;
    }

    @Override
    public Map<Long, List<MerchantSupplier>> getAllAndStateTrueGroupByMerchantId() {

        Map<Long, List<MerchantSupplier>> res = new HashMap<>();
        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andStateEqualTo(true);
        List<MerchantSupplier> list = merchantSupplierMapper.selectByExample(merchantSupplierExample);

        Map<Long, String> m = new HashMap();
        for (MerchantSupplier merchantSupplier : list) {
            //先找出所有的商户ID
            m.put(merchantSupplier.getMerchantId(), "");
        }

        for (Map.Entry<Long, String> entry : m.entrySet()) {
            List resm = new ArrayList();
            for (MerchantSupplier merchantSupplier : list) {
                //先找出所有的商户ID
                if (merchantSupplier.getMerchantId().equals(entry.getKey())) {
                    resm.add(merchantSupplier);
                }
            }
            res.put(entry.getKey(), resm);
        }

        return res;
    }

    @Override
    public Map<String, List<MerchantSupplier>> getAllGroupByMerchantIdAndParentIdAndStateTrue() {

        Map<String, List<MerchantSupplier>> map = new HashMap<>();
        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andStateEqualTo(true);
        List<MerchantSupplier> list = merchantSupplierMapper.selectByExample(merchantSupplierExample);
        for (MerchantSupplier merchantSupplier : list) {
            List<MerchantSupplier> aa = new ArrayList<>();
            aa.add(merchantSupplier);
            map.put(merchantSupplier.getMerchantId() + merchantSupplier.getParentMerchantId() + "", aa);
        }
        return map;
    }

    @Override
    public Map<Long, List<MerchantSupplier>> getAllAndStateTrueGroupByMerchantIdAndSupplierIs0() {
        Map<Long, List<MerchantSupplier>> res = new HashMap<>();
        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andStateEqualTo(true).andSupplierTypeEqualTo(0);
        List<MerchantSupplier> list = merchantSupplierMapper.selectByExample(merchantSupplierExample);

        Map<Long, String> m = new HashMap();
        for (MerchantSupplier merchantSupplier : list) {
            //先找出所有的商户ID
            m.put(merchantSupplier.getMerchantId(), "");
        }

        for (Map.Entry<Long, String> entry : m.entrySet()) {
            List resm = new ArrayList();
            for (MerchantSupplier merchantSupplier : list) {
                //先找出所有的商户ID
                if (merchantSupplier.getMerchantId().equals(entry.getKey())) {
                    resm.add(merchantSupplier);
                }
            }
            res.put(entry.getKey(), resm);
        }

        return res;
    }

    @Override
    public List<MerchantSupplier> getByMerchantIdAndSupplierTypeIs1(Long id) {

        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andMerchantIdEqualTo(id).andSupplierTypeEqualTo(1).andStateEqualTo(true);
        return merchantSupplierMapper.selectByExample(merchantSupplierExample);
    }

    public MerchantProductSkuDTO getById(List<MerchantProductSkuDTO> list, Long skuId) {

        for (MerchantProductSkuDTO productSkuDTO : list) {
            if (productSkuDTO.getSkuId().equals(skuId)) {
                return productSkuDTO;
            }
        }
        return null;
    }

    @Override
    public List<MerchantSupplier> getByMerchantIdAndParentMerchantId(Long merchantId, Long parentMerchantId) {

        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andParentMerchantIdEqualTo(parentMerchantId).andMerchantIdEqualTo(merchantId);

        return merchantSupplierMapper.selectByExample(merchantSupplierExample);
    }

    @Override
    public List<MerchantProductSkuDTO> getByMerchantIdAndProductIdAndSku(Long merchantId, Long productId, Long skuId) {

        return null;
    }

    @Override
    public List<MerchantSupplier> getByParentMerchantId(Long parentMerchantId) {
        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andParentMerchantIdEqualTo(parentMerchantId);

        return merchantSupplierMapper.selectByExample(merchantSupplierExample);
    }

    @Override
    public List<MerchantSupplier> getByMerchantId(Long merchantId) {
        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andMerchantIdEqualTo(merchantId);
        List<MerchantSupplier> list = merchantSupplierMapper.selectByExample(merchantSupplierExample);

        return list;
    }

    @Override
    public List<MerchantSupplier> getByMerchantIdAndStateTrue(Long merchantId) {
        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andMerchantIdEqualTo(merchantId).andStateEqualTo(true);
        List<MerchantSupplier> list = merchantSupplierMapper.selectByExample(merchantSupplierExample);

        return list;
    }

    public List<MerchantSupplier> getByMerchantIdAndParentIdAndStateTrue(Long merchantId, Long parentId) {
        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andMerchantIdEqualTo(merchantId).andStateEqualTo(true).andParentMerchantIdEqualTo(parentId);
        List<MerchantSupplier> list = merchantSupplierMapper.selectByExample(merchantSupplierExample);
        return list;
    }

    public static void main(String[] args) {
        BigDecimal price = new BigDecimal(10);

        BigDecimal price1 = price.add(price.multiply(new BigDecimal(0.1)));
        price1.add(price1.multiply(new BigDecimal(0.1)));//二次加价
        System.out.println(price1.doubleValue());
        System.out.println(price.multiply(new BigDecimal(0.1)));

    }

    @Override
    public List<MerchantSupplier> getByMerchantIdAndSupplierTypeIs0(Long id) {
        MerchantSupplierExample merchantSupplierExample = new MerchantSupplierExample();
        merchantSupplierExample.createCriteria().andMerchantIdEqualTo(id).andSupplierTypeEqualTo(0).andStateEqualTo(true);
        return merchantSupplierMapper.selectByExample(merchantSupplierExample);
    }

    @Override
    public Long insert(MerchantSupplier merchantSupplier) {
        merchantSupplierMapper.insert(merchantSupplier);
        return merchantSupplier.getId();
    }

}
